"""Definition of the house content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata
from Products.ATContentTypes.content.newsitem import ATNewsItem,ATNewsItemSchema

# -*- Message Factory Imported Here -*-
from my315ok.fangcan import fangcanMessageFactory as _


from my315ok.fangcan.interfaces import Ihouse
from my315ok.fangcan.config import PROJECTNAME
from DateTime.DateTime import DateTime


houseSchema = ATNewsItemSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.StringField(
        'deposit',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"deposit"),
            description=_(u""),
        ),
    ),


    atapi.FloatField(
        'longitude',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"longitude"),
            description=_(u""),
        ),
        default=_(u"112.885666"),
        validators=('isDecimal'),
    ),


    atapi.FloatField(
        'latitude',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"latitude"),
            description=_(u""),
        ),
        default=_(u"27.879506"),
        validators=('isDecimal'),
    ),




    atapi.StringField(
        'category',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.fangcan.category",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"category"),
            description=_(u""),            
        ),
        required=True,
        default="1",
    ),


    atapi.StringField(
        'House_direction',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"house direction"),
            description=_(u""),
        ),
    ),


    atapi.DateTimeField(
        'Create_time',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"created time"),
            description=_(u""),
            starting_year=1990,
            show_hm=0,
        ),
        validators=('isValidDate'),
    ),


    atapi.StringField(
        'Rent_unitprice',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"rent unit price"),
            description=_(u""),
        ),
    ),


    atapi.FloatField(
        'Sellingprice',
        searchable = True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"selling price"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Curr_state',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"current state"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Decorate',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"decorate"),
            description=_(u""),
        ),
    ),


    atapi.DateTimeField(
        'Overday',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"over day"),
            description=_(u""),
            starting_year=2000,
            show_hm=0,
        ),
        validators=('isValidDate'),
    ),


    atapi.StringField(
        'Record_no',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"record number"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Level',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"level"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Use',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"house using"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Owner_name',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"owner name"),
            description=_(u""),
        ),
    ),


    atapi.DateTimeField(
        'Lastfollow_time',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"last follow time"),
            description=_(u""),
            starting_year=2000,
            show_hm=0,
        ),
        validators=('isValidDate'),
    ),


    atapi.StringField(
        'House_no',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"house number"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Area',
        searchable = True,
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.fangcan.area",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"area"),
            description=_(u""),            
        ),
        required=True,
        default="yuhu",        
    ),


    atapi.StringField(
        'Commission_no',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"commission number"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Country',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"country"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Biztype',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.fangcan.biztype",
        enforceVocabulary=True,        
        widget=atapi.SelectionWidget(
            label=_(u"biz type"),
            description=_(u""),
        ),
        required=True,
        default="1",
    ),


    atapi.IntegerField(
        'Mianji',
        searchable = True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"house mianji"),
            description=_(u""),
        ),
         validators=('isInt'),
    ),


    atapi.StringField(
        'Estate_type',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"estate type"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Card_no',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"card number"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Propertyright',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"property right"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'decorate_level',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"decorate level"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Pay_commision',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"pay commision"),
            description=_(u""),
        ),
#        validators=('isInt'),
    ),


    atapi.IntegerField(
        'Rent_price',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"rent price"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.IntegerField(
        'Sale_unitprice',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"unit price for sale"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.StringField(
        'Address',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"address"),
            description=_(u""),
        ),
        required=True,
    ),



    atapi.StringField(
        'Pay_type',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"pay type"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Commissiontype',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"commission type"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Housestate',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"house state"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Owner_phone',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"owner phone"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'Owner_orga_name',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"department name"),
            description=_(u""),
        ),
    ),


    atapi.DateTimeField(
        'Build_year',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"build year"),
            description=_(u""),
            starting_year=1990,
            show_hm=0,
        ),
         validators=('isValidDate'),
    ),


    atapi.IntegerField(
        'Layer',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"layer"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


    atapi.DateTimeField(
        'Commissiondate',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"commission date"),
            description=_(u""),
            starting_year=2000,
            show_hm=0,
        ),
        validators=('isValidDate'),
    ),


    atapi.IntegerField(
        'Room',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"room"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),
    
    
    atapi.IntegerField(
        'Drawing_room',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"drawing room"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),
    
    

    atapi.StringField(
        'Balcony',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"balcony"),
            description=_(u""),
        ),
    ),


    atapi.StringField(
        'toilet',
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"toilet"),
            description=_(u""),
        ),
    ),



    atapi.DateTimeField(
        'Lastmodify_time',
        storage=atapi.AnnotationStorage(),
        default_method = 'getDefaultTime',
        widget=atapi.CalendarWidget(
            label=_(u"last modify time"),
            description=_(u""),
            starting_year=2000,
            show_hm=0,
        ),
        validators=('isValidDate'),
    ),


    atapi.StringField(
        'Bigarea',
        storage=atapi.AnnotationStorage(),
        vocabulary_factory=u"my315ok.fangcan.bigarea",
        enforceVocabulary=True,
        widget=atapi.SelectionWidget(
            label=_(u"city area"),
            description=_(u""),            
        ),
        required=True,
        default="xiangtanshi",
    ),


    atapi.StringField(
        'Estate',
        searchable = True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.StringWidget(
            label=_(u"building dictionary"),
            description=_(u""),
        ),
        required=True,
        default="sanpan",
    ),


    atapi.TextField(
        'Remark',
        storage=atapi.AnnotationStorage(),
        widget=atapi.TextAreaWidget(
            label=_(u"remark"),
            description=_(u""),
        ),
    ),


    atapi.IntegerField(
        'Total_layer',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"total layer"),
            description=_(u""),
        ),
        validators=('isInt'),
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

houseSchema['title'].storage = atapi.AnnotationStorage()
houseSchema['description'].storage = atapi.AnnotationStorage()
houseSchema['imageCaption'].widget.visible = 0
houseSchema['text'].widget.visible = 1
houseSchema['text'].widget.allow_file_upload=False
houseSchema['image'].widget.description = _(u'main photo of the house')
houseSchema['image'].valisators=()
houseSchema.moveField('text', pos='bottom')

schemata.finalizeATCTSchema(houseSchema, moveDiscussion=False)


class house(ATNewsItem):
    """house information"""
    implements(Ihouse)

    meta_type = "house"
    schema = houseSchema
    _at_rename_after_creation = False


    def getDefaultTime(self):  # function to return the current date and time
        return DateTime()

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    deposit = atapi.ATFieldProperty('deposit')

    longitude = atapi.ATFieldProperty('longitude')

    latitude = atapi.ATFieldProperty('latitude')

    toilet = atapi.ATFieldProperty('toilet')

    category = atapi.ATFieldProperty('category')

    House_direction = atapi.ATFieldProperty('House_direction')

    Create_time = atapi.ATFieldProperty('Create_time')

    Rent_unitprice = atapi.ATFieldProperty('Rent_unitprice')

    Sellingprice = atapi.ATFieldProperty('Sellingprice')

    Curr_state = atapi.ATFieldProperty('Curr_state')

    Decorate = atapi.ATFieldProperty('Decorate')

    Overday = atapi.ATFieldProperty('Overday')

    Record_no = atapi.ATFieldProperty('Record_no')

    Level = atapi.ATFieldProperty('Level')

    Use = atapi.ATFieldProperty('Use')

    Owner_name = atapi.ATFieldProperty('Owner_name')

    Lastfollow_time = atapi.ATFieldProperty('Lastfollow_time')

    House_no = atapi.ATFieldProperty('House_no')

    Area = atapi.ATFieldProperty('Area')

    Commission_no = atapi.ATFieldProperty('Commission_no')

    Country = atapi.ATFieldProperty('Country')

    Biztype = atapi.ATFieldProperty('Biztype')

    Mianji = atapi.ATFieldProperty('Mianji')

    Estate_type = atapi.ATFieldProperty('Estate_type')

    Card_no = atapi.ATFieldProperty('Card_no')

    Propertyright = atapi.ATFieldProperty('Propertyright')

    decorate_level = atapi.ATFieldProperty('decorate_level')

    Pay_commision = atapi.ATFieldProperty('Pay_commision')

    Rent_price = atapi.ATFieldProperty('Rent_price')

    Sale_unitprice = atapi.ATFieldProperty('Sale_unitprice')

    Address = atapi.ATFieldProperty('Address')

    Drawing_room = atapi.ATFieldProperty('Drawing_room')

    Pay_type = atapi.ATFieldProperty('Pay_type')

    Balcony = atapi.ATFieldProperty('Balcony')

    Commissiontype = atapi.ATFieldProperty('Commissiontype')

    Housestate = atapi.ATFieldProperty('Housestate')

    Owner_phone = atapi.ATFieldProperty('Owner_phone')

    Owner_orga_name = atapi.ATFieldProperty('Owner_orga_name')

    Build_year = atapi.ATFieldProperty('Build_year')

    Layer = atapi.ATFieldProperty('Layer')

    Commissiondate = atapi.ATFieldProperty('Commissiondate')

    Room = atapi.ATFieldProperty('Room')

    Lastmodify_time = atapi.ATFieldProperty('Lastmodify_time')

    Bigarea = atapi.ATFieldProperty('Bigarea')

    Estate = atapi.ATFieldProperty('Estate')

    Remark = atapi.ATFieldProperty('Remark')

    Total_layer = atapi.ATFieldProperty('Total_layer')


atapi.registerType(house, PROJECTNAME)
